/**********************************************
*  Classes:   CdnRenderer
*  Desc:      Base renderer class. Renders geometry
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#include "CdnRenderer.h"
#include "GLRenderer.h"
#include "CdnD3d9Renderer.h"
#include "MaterialProperty.h"
#include "Camera.h"
#include "SkyBox.h"
//------------------------------------------------------
CdnRenderer* CdnRenderer::m_pInstance = 0;
CdnRenderer::RendererType CdnRenderer::m_eType = CdnRenderer::TYPE_OPENGL;
//------------------------------------------------------
/**
* ctor
*/
CdnRenderer::CdnRenderer() :
m_iWidth(1024),
m_iHeight(768),
m_fAspectRatio(1.3333f),
m_bWindowCreated(false),
m_bFullscreen(false),
m_hInstance(0),
m_hWnd(0),
m_hDC(0),
m_bInitialized(false),
m_bDrawBounds(false),
m_cfClassName("CodenClass")

{

}
//------------------------------------------------------
/**
* dtor
*/
CdnRenderer::~CdnRenderer()
{
	m_spCamera = CameraPtr();

	m_spSkyBox = SkyBoxPtr();

	UnloadGeometry();
	
}
//------------------------------------------------------
/**
* Gets single instance
*/
CdnRenderer* CdnRenderer::GetInstance()
{
	if (!m_pInstance)
	{
		if (m_eType == TYPE_OPENGL)
		{
			m_pInstance = new GLRenderer();
		}		
		else if (m_eType == TYPE_D3D)
		{	
			m_pInstance = new CdnD3d9Renderer();
		}
	}

	return m_pInstance;
}
//------------------------------------------------------
/**
* Destroys single instance
*/
void CdnRenderer::Destroy()
{
	if (m_pInstance)
	{
		delete m_pInstance;
		m_pInstance = 0;
	}
}

//----------------------------------------------
/**
* Tests if an AABB of a node
* is inside the view frustrum
*/
bool CdnRenderer::IsVisible(TransformNode* node)
{
	const BoundingBox& b = node->GetBoundingBox();
	return b.IsInside(m_spCamera->GetFrustrum());
}

